/*
 * WeakPointer.hpp
 *
 *  Created on: Sep 29, 2010
 *      Author: nicoabie
 */

#ifndef WEAKPOINTER_HPP_
#define WEAKPOINTER_HPP_

#include "SmartPointer.hpp"

template<class T, class Cache>
class WeakPointer
{
public:
	WeakPointer();
	WeakPointer(const T* x);
	~WeakPointer();
	template<class U>
	WeakPointer(const WeakPointer<U,Cache>& x);
	template<class U>
	WeakPointerPointer& operator=(SmartPointer<U,Cache>& x);
	template<class U>
	WeakPointer(const WeakPointer<U,Cache>& x);
	template<class U>
	SmartPointer& operator=(SmartPointer<U,Cache>& x);
	T& operator*() const;
	T* operator->() const;
	RefCounter& getCounter();
	T& get();
	void setID(long id);
	long getID();
	void read(id);
	void write(id);
	bool dirty();

private:
	RefCounter counter;
	T* pRefered;
	long id;
	void release();

};

#endif /* WEAKPOINTER_HPP_ */
